package com.example.wblog.dao;

import com.example.wblog.model.LoginTicket;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface LoginTicketDAO {
    String TABLE_NAME = " login_ticket ";
    String INSERT_FIELD = " ticket, expired, status, user_id ";
    String SELECT_FIELD = " id, " + INSERT_FIELD;

    @Insert({"insert into", TABLE_NAME, "(", INSERT_FIELD, ") values (#{ticket}, #{expired}, #{status}, #{userId})"})
    int add(LoginTicket ticket);

    @Select({"select", SELECT_FIELD, "from", TABLE_NAME, "where ticket=#{ticket}"})
    LoginTicket selectByTicket(String ticket);

    @Delete({"delete from", TABLE_NAME, "where ticket = #{ticket}"})
    void deleteByTicket(String ticket);
}
